package io.github.wanggit.antrpc.client.zk.zknode;

import io.github.wanggit.antrpc.commons.bean.Host;
import io.github.wanggit.antrpc.commons.bean.RegisterBeanMethod;

import java.util.List;
import java.util.Map;
import java.util.Objects;

public class NodeHostEntity extends Host {

    private static final long serialVersionUID = -7230598907332171765L;
    private Long registerTs;
    private List<String> methodStrs;
    private Map<String, RegisterBeanMethod> methodMap;
    private String className;

    public NodeHostEntity() {}

    public NodeHostEntity(String ip, Integer port) {
        super(ip, port);
    }

    public Map<String, RegisterBeanMethod> getMethodMap() {
        return methodMap;
    }

    public void setMethodMap(Map<String, RegisterBeanMethod> methodMap) {
        this.methodMap = methodMap;
    }

    public Long getRegisterTs() {
        return registerTs;
    }

    public void setRegisterTs(Long registerTs) {
        this.registerTs = registerTs;
    }

    public List<String> getMethodStrs() {
        return methodStrs;
    }

    public void setMethodStrs(List<String> methodStrs) {
        this.methodStrs = methodStrs;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof NodeHostEntity)) {
            return false;
        }
        NodeHostEntity other = (NodeHostEntity) obj;
        return Objects.equals(other.getHostInfo(), getHostInfo())
                && Objects.equals(other.getClassName(), getClassName());
    }

    @Override
    public int hashCode() {
        return getHostInfo().hashCode() + (null == getClassName() ? 0 : getClassName().hashCode());
    }

    @Override
    public String toString() {
        return "ip="
                + getIp()
                + ", port="
                + getPort()
                + ", className="
                + getClassName()
                + ", registerTs="
                + getRegisterTs()
                + ", methodStrs="
                + getMethodStrs();
    }
}
